AI Verified
Display Prices With + Without Tax
This code snippet is a part of a WordPress plugin or theme customization that modifies the display of prices in the WooCommerce plugin, specifically the suffix that appears after the product price. The `add_filter` function is a WordPress hook that allows you to modify the output of a specific function or filter. In this case, it hooks into the `woocommerce_get_price_suffix` filter with a priority of 99 (a higher number means it executes later in the filtering process) and accepts 4 parameters. The function `bbloomer_add_price_suffix_price_inc_tax` is the callback function that is executed when the `woocommerce_get_price_suffix` filter is triggered. It takes four parameters: `$suffix`, `$product`, `$price`, and `$qty`. Within the callback function, the code modifies the `$suffix` variable, which represents the price suffix that is displayed after the product price. The new suffix is composed of two small HTML elements wrapped around the text and the calculated price, indicating the inclusion or exclusion of taxes. Here's a breakdown of what happens in the callback function: 1. The `$suffix` variable is assigned a new value. 2. The new value consists of a text string `' <small>ex. TAX</small> - '` followed by the price including tax calculated using the `wc_get_price_including_tax()` function, and finally, another small HTML element `'<small>inc. TAX</small>'`. 3. The modified `$suffix` variable is then returned from the function. By using this code, the output of the product price in WooCommerce will include a small HTML text indicating whether the price is excluding or including tax, as specified in the suffix.
PHP
Voted: 0 by 0 user(s)
The author has provided the following URL that may be helpful to setting up or using this snippet:
https://www.businessbloomer.com/woocommerce-prices-inc-and-ex-tax/Scroll down to see more snippets from this codevault.
The author has indicated that this snippet is compatable up to wordpress version: 6.1
Our AI bot has checked this snippet is compatable up to wordpress version: 6.1
Free & Pro
Download this snippet by clicking the download button, then head over to the Code Snippet Plugin settings in your wordpress admin dashboard, select the import menu then upload this file to import into your wordpress site.
Pro Only (Coming Soon)
You will be able to click a button and sync this snippet to your wordpress site automatically and from your dashboard manage all code snippets across all your wordpress sites that have the Code Snippets Pro plugin installed.
Last modified:
16/06/2023
This snippet has the following status:
AI Verified
This snippet has been tested by our AI bot, see any comments below.
AI Bot Comments:
Found 0 vulnerabilities
0
Please see some snippets below related to this snippet..
WooCommerce
AI Verified
Added: 1 year ago
Last Updated: 1 day ago
This snippet automatically creates a coupon code when an order is placed and lets the customer know to share said coupon code to give their friend money off. Specifically, this code creates a coupon c...
WooCommerce
AI Verified
Added: 5 months ago
Last Updated: 5 months ago
Add a mandatory delivery date field between 2 to 7 days from today.
WooCommerce
AI Verified
These are some popular snippets from this users codevault..
General
AI Verified
Added: 1 year ago
Last Updated: 3 days ago
This code defines a function named default_post_metadata__thumbnail_id that modifies the value of the _thumbnail_id metadata field for a post. The function takes five arguments: $value: The current...
WordPress Admin
AI Verified
Added: 1 year ago
Last Updated: 4 months ago
This will disable comments on the entire site
WordPress Admin
AI Verified
Added: 1 year ago
Last Updated: 9 months ago
This will disable automatic updates
Category
Snippet Status